/*
    fracgen-c : Fractal Generator (using concurrency)
    Copyright (C) 2010 Arpit Sud, Sri Teja Basava & Sidartha Gracias

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.awt.*;
import java.awt.image.*;


public class FractalImage extends Component{
	/* This class obtains the BufferedImage from ComplexPlane
	 * and draws it as a graphic
	 */
	private ComplexPlane cp;
	
	// Redefining the paint method
	public void paint (Graphics g) {
		BufferedImage bi = cp.getImage();
		Graphics2D g2 = (Graphics2D)g;
		g2.drawImage(bi, 0, 0, this);
		Dimension imageSize = getPreferredSize();
		setSize(imageSize.width,imageSize.height);
	}
	// Redefining the update method
	public void update (Graphics g) {
		BufferedImage bi = cp.getImage();
		Graphics2D g2 = (Graphics2D)g;
		g2.drawImage(bi, 0, 0, this);
		Dimension imageSize = getPreferredSize();
		setSize(imageSize.width,imageSize.height);
	}	
	
	public FractalImage(ComplexPlane cmp) { //Constructor
		cp = cmp;
	}
	// Redefining the getPreferredSize method
    public Dimension getPreferredSize() {
    		BufferedImage bi = cp.getImage();
    		int w = bi.getWidth();
    		int h = bi.getHeight();
    		Dimension imageSize = new Dimension(w,h);
          return imageSize;
    }
}
